package com.antipov.odp.rmi.server;

import com.antipov.odp.rmi.intf.PointService;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

/**
 * Created with IntelliJ IDEA.
 * User: Andrew Antipov
 * Date: 19.02.14
 * Time: 1:53
 */
public class Application {

	public static void main(String[] args) {
		try {
			LocateRegistry.createRegistry(1099);
			System.out.println("java RMI registry created.");
		} catch (RemoteException e) {
			System.out.println("java RMI registry already exists.");
		}

		if (System.getSecurityManager() == null) {
			System.setSecurityManager(new SecurityManager());
		}

		try {
			String name = "PointService";
			PointServiceBean pointServiceBean = new PointServiceBean();
			PointService stub = (PointService) UnicastRemoteObject.exportObject(pointServiceBean, 0);
			Registry registry = LocateRegistry.getRegistry();
			registry.rebind(name, stub);
			System.out.println("PeerServer bound in registry");
		} catch (Exception e) {
			System.err.println("RMI server exception:" + e);
			e.printStackTrace();
		}
	}
}
